import ajax from '@/utils/ajax'
import dialog from '@/utils/dialog'
import cookie from '@/utils/cookie'
export default function (data) {
  return ajax({
    url: `/login`,
    loading: '登录中...',
    data: {
      json: {
        iphone: data.tel,
        code: data.numcode,
        type: data.wxcode ? '1' : '0',
        opeenIdCode: data.wxcode
      }
    }
  }).then(resdata => {
    if (resdata.token) {
      cookie.setCookie('name', resdata.name)
      cookie.setCookie('token', resdata.token)
    }
    return resdata
  }).catch((msg) => dialog.showToast(msg || '请求失败'))
}
